package com.hsc.yalebao.tabIndex;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Editable;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.hsc.yalebao.adapter.ChatMsgViewAdpater;
import com.hsc.yalebao.base.BaseActivity;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.db.ChatMessageUtil;
import com.hsc.yalebao.face.EmojiFragment;
import com.hsc.yalebao.face.FaceBean;
import com.hsc.yalebao.face.FaceEditText;
import com.hsc.yalebao.face.FaceFragment;
import com.hsc.yalebao.face.FaceUtil;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.model.ChatMsgEntity;
import com.hsc.yalebao.model.UserBaseBean;
import com.hsc.yalebao.tools.DateUtil;
import com.hsc.yalebao.tools.SharedPreferencesUtil;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.hsc.yalebao.weight.MyDialogCancelAndOk;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.util.StringUtils;

public class CustomServiceActivity extends BaseActivity
  implements View.OnClickListener
{
  public static final String HOST = AppConstants.IMIP;
  public static final int PORT = 5222;
  public static final String SERVICE = "gmail.com";
  public static CustomServiceActivity customServiceActivity;
  public String PASSWORD = "anonymous";
  private String TAG = "-CustomServiceActivity-";
  public String USERNAME = "anonymous";
  private ChatMessageUtil chatMessageUtil;
  public ChatMsgViewAdpater chatMsgViewAdpater;
  private XMPPConnection connection;
  ConnectionListener connectionListener = new ConnectionListener()
  {
    public void connectionClosed()
    {
      LogUtils.i("connection", "connectionClosed");
      try
      {
        if (CustomServiceActivity.this.connection != null)
          CustomServiceActivity.this.connection = null;
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }

    public void connectionClosedOnError(Exception paramAnonymousException)
    {
      LogUtils.i("connection", "connectionClosedOnError");
      CustomServiceActivity.this.connectToXmpp();
    }

    public void reconnectingIn(int paramAnonymousInt)
    {
      LogUtils.i("connection", "reconnectingIn");
    }

    public void reconnectionFailed(Exception paramAnonymousException)
    {
      LogUtils.i("connection", "reconnectionFailed");
    }

    public void reconnectionSuccessful()
    {
      LogUtils.i("connection", "reconnectionSuccessful");
    }
  };
  private View contentView;
  private Context context;
  private String customer;
  public ArrayList<ChatMsgEntity> data;
  private FaceEditText edit_text_input;
  private Handler emojiHandler = new Handler()
  {
    public void handleMessage(android.os.Message paramAnonymousMessage)
    {
      String str = (String)paramAnonymousMessage.obj;
      CustomServiceActivity.this.sendMeg(str);
    }
  };
  private List<EmojiFragment> emojifragments;
  private Handler faceHandler = new Handler()
  {
    public void handleMessage(android.os.Message paramAnonymousMessage)
    {
      String str = (String)paramAnonymousMessage.obj;
      if (str.equals("[DELETE_ICON]"))
      {
        CustomServiceActivity.this.deleOneString();
        return;
      }
      int i = CustomServiceActivity.this.edit_text_input.getSelectionStart();
      Editable localEditable = CustomServiceActivity.this.edit_text_input.getText();
      localEditable.insert(i, str);
      int j = i + str.length();
      CustomServiceActivity.this.edit_text_input.setText(localEditable);
      CustomServiceActivity.this.edit_text_input.setSelection(j);
    }
  };
  private List<FaceFragment> fragments;
  private ImageView img_biaoqing_face;
  private ImageView img_emoji;
  private ImageView img_face;
  private ImageView img_fasong;
  private ImageView img_fasong_face;
  private ImageView img_touzhu;
  private boolean isScrollLastRoll;
  private ImageView iv_title_right;
  private RadioGroup layoutDotsFace;
  private LinearLayout lin_face;
  private RelativeLayout lin_root;
  public ListView list_chat_msg;
  private int memberid;
  MyDialogCancelAndOk myDialogCancelAndOk;
  private String nickname;
  View.OnClickListener onClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      default:
        return;
      case 2131099699:
      }
      CustomApplication.app.finishActivity(CustomServiceActivity.this);
    }
  };
  View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener()
  {
    public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
    {
      if (!paramAnonymousBoolean)
      {
        CustomServiceActivity.this.closeWindowSoftInput(paramAnonymousView);
        CustomServiceActivity.this.lin_face.setVisibility(8);
      }
    }
  };
  View.OnKeyListener onKey = new View.OnKeyListener()
  {
    public boolean onKey(View paramAnonymousView, int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
    {
      if ((paramAnonymousInt == 66) && (paramAnonymousKeyEvent.getAction() == 0))
      {
        CustomServiceActivity.this.sendMsg();
        return true;
      }
      return false;
    }
  };
  AbsListView.OnScrollListener onScrollListener = new AbsListView.OnScrollListener()
  {
    public void onScroll(AbsListView paramAnonymousAbsListView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
      if ((paramAnonymousInt1 + paramAnonymousInt2 == paramAnonymousInt3) && (paramAnonymousInt3 > 0));
      for (CustomServiceActivity.this.isScrollLastRoll = true; ; CustomServiceActivity.this.isScrollLastRoll = false)
      {
        LogUtils.i(CustomServiceActivity.this.TAG, "isScrollLastRoll：" + CustomServiceActivity.this.isScrollLastRoll);
        return;
      }
    }

    public void onScrollStateChanged(AbsListView paramAnonymousAbsListView, int paramAnonymousInt)
    {
      switch (paramAnonymousInt)
      {
      default:
      case 1:
      case 0:
      }
      do
      {
        return;
        try
        {
          ((InputMethodManager)CustomServiceActivity.this.getSystemService("input_method")).hideSoftInputFromWindow(CustomServiceActivity.this.edit_text_input.getWindowToken(), 0);
          CustomServiceActivity.this.lin_face.setVisibility(8);
          return;
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
          return;
        }
        LogUtils.d(CustomServiceActivity.this.TAG, "listView不滚动时");
      }
      while (paramAnonymousAbsListView.getLastVisiblePosition() != -1 + paramAnonymousAbsListView.getCount());
      LogUtils.i(CustomServiceActivity.this.TAG, "listView 滚动到了底部");
    }
  };
  PacketListener packetListener = new PacketListener()
  {
    public void processPacket(Packet paramAnonymousPacket)
    {
      if (CustomServiceActivity.this.connection == null)
        CustomServiceActivity.this.connectToXmpp();
      while (CustomServiceActivity.this.connection.isConnected())
      {
        org.jivesoftware.smack.packet.Message localMessage = (org.jivesoftware.smack.packet.Message)paramAnonymousPacket;
        String str1 = localMessage.getBody();
        String str2 = StringUtils.parseBareAddress(localMessage.getFrom());
        LogUtils.i(CustomServiceActivity.this.TAG, "Text Recieved " + str1 + " from " + str2 + " to " + localMessage.getTo());
        String[] arrayOfString1 = str2.split("@");
        if (arrayOfString1 != null)
          CustomServiceActivity.this.customer = arrayOfString1[0];
        if (!CustomApplication.app.isLogin)
        {
          String[] arrayOfString2 = localMessage.getTo().split("@");
          if (arrayOfString2 != null)
            CustomServiceActivity.this.USERNAME = arrayOfString2[0];
        }
        LogUtils.i(CustomServiceActivity.this.TAG, "customer:" + CustomServiceActivity.this.customer);
        String str3 = localMessage.getMessagedirect();
        LogUtils.e(CustomServiceActivity.this.TAG, "messageDirect:" + str3);
        String str4 = localMessage.getRoomid();
        LogUtils.e(CustomServiceActivity.this.TAG, "roomId:" + str4);
        if ("2".equals(str3))
        {
          String str5 = localMessage.getNickname();
          String str6 = localMessage.getPicurl();
          String str7 = localMessage.getSendtime();
          LogUtils.i(CustomServiceActivity.this.TAG, "nickName:" + str5);
          LogUtils.i(CustomServiceActivity.this.TAG, "picUrl:" + str6);
          LogUtils.i(CustomServiceActivity.this.TAG, "sendTime:" + str7);
          ChatMsgEntity localChatMsgEntity = new ChatMsgEntity();
          localChatMsgEntity.setBody(str1);
          localChatMsgEntity.setMessagetype("1");
          localChatMsgEntity.setNickname(str5);
          localChatMsgEntity.setPicurl(str6);
          localChatMsgEntity.setSendtime(str7);
          localChatMsgEntity.setComMsg(0);
          if (CustomServiceActivity.this.data != null)
            CustomServiceActivity.this.data.add(localChatMsgEntity);
          CustomServiceActivity.this.refeshListView();
          LogUtils.e(CustomServiceActivity.this.TAG, "存入接收的消息");
          CustomServiceActivity.this.chatMessageUtil.addMessage(CustomServiceActivity.this.USERNAME, localChatMsgEntity);
        }
        return;
      }
      CustomServiceActivity.this.connectToXmpp();
    }
  };
  Runnable refeshRunnable = new Runnable()
  {
    public void run()
    {
      CustomServiceActivity.this.setAdapterDatas();
    }
  };
  private String roomId = "0|kefu";
  private int screenHeight;
  private String userAccount = "anonymous";
  private String userLogo;
  private ViewPager viewPagerFace;
  private View view_title;
  private ViewPager vp_emoji;

  private RadioButton createRadioButton()
  {
    RadioButton localRadioButton = new RadioButton(this.context);
    RadioGroup.LayoutParams localLayoutParams = new RadioGroup.LayoutParams(15, 15);
    localLayoutParams.rightMargin = 5;
    localRadioButton.setLayoutParams(localLayoutParams);
    localRadioButton.setButtonDrawable(new BitmapDrawable());
    localRadioButton.setBackgroundResource(2130838224);
    return localRadioButton;
  }

  private void deleOneString()
  {
    int i = this.edit_text_input.getSelectionStart();
    Editable localEditable = this.edit_text_input.getText();
    String str = this.edit_text_input.getText().toString().substring(0, i);
    if (str.lastIndexOf("]") == i - 1)
    {
      j = str.lastIndexOf("[");
      if (j == -1);
    }
    while (i == 0)
    {
      int j;
      localEditable.delete(j, i);
      do
        return;
      while (i == 0);
      localEditable.delete(i - 1, i);
      return;
    }
    localEditable.delete(i - 1, i);
  }

  private void disConnectionToXmpp()
  {
    try
    {
      if (this.connection != null)
        this.connection.disconnect();
      this.connection = null;
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  private void init()
  {
    this.data = new ArrayList();
    this.screenHeight = CustomApplication.app.displayMetrics.heightPixels;
    this.myDialogCancelAndOk = new MyDialogCancelAndOk(this.context);
    this.lin_root = ((RelativeLayout)findViewById(2131099807));
    this.list_chat_msg = ((ListView)this.contentView.findViewById(2131099808));
    this.list_chat_msg.setOnScrollListener(this.onScrollListener);
    this.img_biaoqing_face = ((ImageView)this.contentView.findViewById(2131100037));
    this.img_biaoqing_face.setOnClickListener(this);
    this.img_fasong_face = ((ImageView)this.contentView.findViewById(2131100036));
    this.img_face = ((ImageView)this.contentView.findViewById(2131100034));
    this.img_emoji = ((ImageView)this.contentView.findViewById(2131100035));
    this.img_fasong_face.setOnClickListener(this);
    this.img_face.setOnClickListener(this);
    this.img_emoji.setOnClickListener(this);
    this.edit_text_input = ((FaceEditText)this.contentView.findViewById(2131100038));
    this.edit_text_input.setOnFocusChangeListener(this.onFocusChangeListener);
    this.edit_text_input.setOnKeyListener(this.onKey);
    this.img_fasong = ((ImageView)this.contentView.findViewById(2131100039));
    this.img_fasong.setOnClickListener(this);
    this.viewPagerFace = ((ViewPager)findViewById(2131100031));
    this.vp_emoji = ((ViewPager)findViewById(2131100032));
    if (this.chatMsgViewAdpater == null)
      this.chatMsgViewAdpater = new ChatMsgViewAdpater(this.context, this.data);
    this.list_chat_msg.setAdapter(this.chatMsgViewAdpater);
    loadDatasFormDb();
    setTitle(8, 0, 2130837809, "客服", 0, 8, 8, 0, true);
    RelativeLayout.LayoutParams localLayoutParams = (RelativeLayout.LayoutParams)this.viewPagerFace.getLayoutParams();
    localLayoutParams.height = (1 * this.screenHeight / 3);
    this.viewPagerFace.setLayoutParams(localLayoutParams);
    this.vp_emoji.setLayoutParams(localLayoutParams);
    this.lin_face = ((LinearLayout)findViewById(2131100030));
    this.lin_face.setVisibility(8);
    this.layoutDotsFace = ((RadioGroup)findViewById(2131100033));
    this.layoutDotsFace.setVisibility(0);
  }

  private void initEmoji()
  {
    this.img_face.setBackgroundColor(0);
    this.img_emoji.setBackgroundColor(-2894893);
    this.viewPagerFace.setVisibility(8);
    this.vp_emoji.setVisibility(0);
    this.layoutDotsFace.removeAllViews();
    this.emojifragments = new ArrayList();
    List localList = FaceUtil.getFaceList(this.context, "xiaozhu_default_string");
    int i = localList.size();
    LogUtils.i(this.TAG, "allSize" + i);
    ArrayList localArrayList = new ArrayList();
    for (int j = 0; ; j++)
    {
      if (j >= localList.size())
      {
        EmojiPagerAdapter localEmojiPagerAdapter = new EmojiPagerAdapter(getSupportFragmentManager());
        this.vp_emoji.setAdapter(localEmojiPagerAdapter);
        LogUtils.i(this.TAG, "更新adapter" + localEmojiPagerAdapter.getCount());
        this.vp_emoji.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
          public void onPageScrollStateChanged(int paramAnonymousInt)
          {
          }

          public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2)
          {
          }

          public void onPageSelected(int paramAnonymousInt)
          {
          }
        });
        return;
      }
      localArrayList.add((FaceBean)localList.get(j));
      if ((localArrayList.size() == 8) || (j == -1 + localList.size()))
      {
        EmojiFragment localEmojiFragment = new EmojiFragment();
        localEmojiFragment.setFaces(localArrayList);
        localEmojiFragment.setHandler(this.emojiHandler);
        this.emojifragments.add(localEmojiFragment);
        LogUtils.i(this.TAG, "创建一个图片gradview=" + localArrayList.size());
        localArrayList = new ArrayList();
      }
    }
  }

  private void initFace()
  {
    this.img_face.setBackgroundColor(-2894893);
    this.img_emoji.setBackgroundColor(0);
    this.vp_emoji.setVisibility(8);
    this.viewPagerFace.setVisibility(0);
    this.layoutDotsFace.removeAllViews();
    this.fragments = new ArrayList();
    List localList1 = FaceUtil.getFaceList(this.context, "face_default_string");
    int i = 0;
    if (localList1 != null)
    {
      if (localList1.size() % 27 != 0)
        break label153;
      i = localList1.size() / 27;
    }
    for (int j = 0; ; j++)
    {
      if (j >= i)
      {
        ViewPagerAdapter localViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        this.viewPagerFace.setAdapter(localViewPagerAdapter);
        this.viewPagerFace.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
          public void onPageScrollStateChanged(int paramAnonymousInt)
          {
          }

          public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2)
          {
          }

          public void onPageSelected(int paramAnonymousInt)
          {
            ((RadioButton)CustomServiceActivity.this.layoutDotsFace.getChildAt(paramAnonymousInt)).setChecked(true);
          }
        });
        ((RadioButton)this.layoutDotsFace.getChildAt(0)).setChecked(true);
        return;
        label153: i = 1 + localList1.size() / 27;
        break;
      }
      new ArrayList();
      int k = 27 * (j + 1);
      if (j == i - 1)
        k = localList1.size();
      List localList2 = localList1.subList(j * 27, k);
      ArrayList localArrayList = new ArrayList();
      localArrayList.addAll(localList2);
      FaceBean localFaceBean = new FaceBean();
      localFaceBean.setKey("[DELETE_ICON]");
      localFaceBean.setImageName("face_delete");
      localArrayList.add(localFaceBean);
      if ((localList2 != null) && (localList2.size() > 1))
      {
        FaceFragment localFaceFragment = new FaceFragment();
        localFaceFragment.setFaces(localArrayList);
        localFaceFragment.setHandler(this.faceHandler);
        this.fragments.add(localFaceFragment);
      }
      this.layoutDotsFace.addView(createRadioButton());
    }
  }

  private void initUserData()
  {
    if (CustomApplication.app.userBaseBean != null)
    {
      this.memberid = CustomApplication.app.userBaseBean.getMemberid();
      this.userLogo = CustomApplication.app.userBaseBean.getUser_logo();
      this.nickname = CustomApplication.app.userBaseBean.getNick_name();
      this.USERNAME = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, this.USERNAME);
      return;
    }
    LogUtils.e(this.TAG, "initUserData()-CustomApplication.app.userBaseBean == null");
  }

  private void loadDatasFormDb()
  {
    showLoadingDialog();
    new Thread(new Runnable()
    {
      public void run()
      {
        if (CustomServiceActivity.this.USERNAME != null);
        while (true)
        {
          int i;
          try
          {
            CustomServiceActivity.this.data = ((ArrayList)CustomServiceActivity.this.chatMessageUtil.getAllMessage(CustomServiceActivity.this.USERNAME));
            if ((CustomServiceActivity.this.userLogo != null) && (!"".equals(CustomServiceActivity.this.userLogo)))
            {
              i = 0;
              int j = CustomServiceActivity.this.data.size();
              if (i < j);
            }
            else
            {
              CustomServiceActivity.this.refeshListView();
              CustomServiceActivity.this.dismissLoadingDialog();
              return;
            }
            ChatMsgEntity localChatMsgEntity = (ChatMsgEntity)CustomServiceActivity.this.data.get(i);
            if (localChatMsgEntity == null)
              break label257;
            String str = localChatMsgEntity.getNickname();
            LogUtils.d(CustomServiceActivity.this.TAG, "nickname:" + CustomServiceActivity.this.nickname);
            LogUtils.i(CustomServiceActivity.this.TAG, "nickName:" + str);
            if (!CustomServiceActivity.this.nickname.equals(str))
              break label257;
            localChatMsgEntity.setPicurl(CustomServiceActivity.this.userLogo);
            CustomServiceActivity.this.chatMessageUtil.updateMessage(CustomServiceActivity.this.USERNAME, localChatMsgEntity);
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
            continue;
          }
          LogUtils.e(CustomServiceActivity.this.TAG, "USERNAME==null");
          continue;
          label257: i++;
        }
      }
    }).start();
  }

  private void refeshListView()
  {
    runOnUiThread(this.refeshRunnable);
  }

  private void sendMsg()
  {
    String str = this.edit_text_input.getText().toString();
    org.jivesoftware.smack.packet.Message localMessage = new org.jivesoftware.smack.packet.Message(this.customer + "@" + HOST, Message.Type.chat);
    if (str.isEmpty())
    {
      UiUtil.showToast(this.context, "消息不能为空哟");
      return;
    }
    localMessage.setMessagetype("1");
    localMessage.setMemberid(this.memberid);
    localMessage.setRoomid("0");
    localMessage.setMessagedirect("1");
    localMessage.setBody(str);
    localMessage.setFrom(this.USERNAME + "@" + HOST);
    try
    {
      if (this.connection == null)
      {
        LogUtils.e(this.TAG, "connection = null");
        this.myDialogCancelAndOk.setMessage("聊天连接失败，确认是否重连");
        this.myDialogCancelAndOk.show();
        this.myDialogCancelAndOk.btn_confirm.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            CustomServiceActivity.this.myDialogCancelAndOk.dismiss();
            CustomServiceActivity.this.connectToXmpp();
          }
        });
        return;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    if (this.connection.isConnected())
    {
      this.connection.sendPacket(localMessage);
      System.out.println("发送XMPP消息成功：" + str);
    }
    while (true)
    {
      ChatMsgEntity localChatMsgEntity = new ChatMsgEntity();
      localChatMsgEntity.setBody(str);
      localChatMsgEntity.setMessagetype("1");
      localChatMsgEntity.setMemberid(this.memberid);
      localChatMsgEntity.setPicurl(this.userLogo);
      localChatMsgEntity.setNickname(this.nickname);
      localChatMsgEntity.setUser_name(this.USERNAME);
      localChatMsgEntity.setSendtime(DateUtil.getNowTime());
      localChatMsgEntity.setComMsg(1);
      this.data.add(localChatMsgEntity);
      this.edit_text_input.setText("");
      closeWindowSoftInput(this.edit_text_input);
      refeshListView();
      LogUtils.e(this.TAG, "存入发送的消息");
      if (!CustomApplication.app.isLogin)
        break;
      this.chatMessageUtil.addMessage(this.USERNAME, localChatMsgEntity);
      return;
      connectToXmpp();
      LogUtils.e(this.TAG, "not connected to server!");
    }
  }

  private void setAdapterDatas()
  {
    if (this.chatMsgViewAdpater != null)
    {
      this.chatMsgViewAdpater.setData(this.data);
      this.chatMsgViewAdpater.setCount(this.data.size());
      this.list_chat_msg.requestLayout();
      this.chatMsgViewAdpater.notifyDataSetChanged();
      this.list_chat_msg.setSelection(this.chatMsgViewAdpater.getCount());
    }
  }

  private void setLinFaceIsVisible()
  {
    if (this.lin_face.getVisibility() == 0)
    {
      this.lin_face.setVisibility(8);
      return;
    }
    this.lin_face.setVisibility(0);
  }

  protected void closeWindowSoftInput(View paramView)
  {
    InputMethodManager localInputMethodManager = (InputMethodManager)getApplicationContext().getSystemService("input_method");
    try
    {
      if ((localInputMethodManager.isActive()) && (getCurrentFocus() != null) && (getCurrentFocus().getWindowToken() != null))
      {
        localInputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 2);
        LogUtils.d(this.TAG, "强制隐藏键盘");
      }
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void connectToXmpp()
  {
    this.USERNAME = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, this.USERNAME);
    showLoadingDialog();
    new Thread(new Runnable()
    {
      public void run()
      {
        CustomServiceActivity.this.setConnection(null);
        XMPPConnection localXMPPConnection = new XMPPConnection(new ConnectionConfiguration(CustomServiceActivity.HOST, 5222, "gmail.com"));
        localXMPPConnection.addConnectionListener(CustomServiceActivity.this.connectionListener);
        try
        {
          localXMPPConnection.connect();
          LogUtils.i(CustomServiceActivity.this.TAG, "Connected to " + localXMPPConnection.getHost());
        }
        catch (XMPPException localXMPPException1)
        {
          try
          {
            CustomServiceActivity.this.setConnection(localXMPPConnection);
            if (CustomApplication.app.isLogin)
            {
              String str1 = CustomApplication.app.userBaseBean.getSource_type();
              String str2 = CustomApplication.app.preferencesUtil.getValue(AppConstants.WX_OPID, "");
              if (str1 != null)
              {
                if (str1.equals("1"))
                {
                  CustomServiceActivity.this.USERNAME = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, CustomServiceActivity.this.USERNAME);
                  CustomServiceActivity.this.userAccount = ("wx|" + str2);
                }
                for (CustomServiceActivity.this.PASSWORD = "123456"; ; CustomServiceActivity.this.PASSWORD = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_PWD, CustomServiceActivity.this.PASSWORD))
                {
                  System.out.println("正常登陆");
                  LogUtils.i(CustomServiceActivity.this.TAG, "Login as " + CustomServiceActivity.this.USERNAME);
                  localXMPPConnection.login(CustomServiceActivity.this.userAccount, CustomServiceActivity.this.PASSWORD, CustomServiceActivity.this.roomId);
                  LogUtils.i(CustomServiceActivity.this.TAG, "Logged in as " + localXMPPConnection.getUser());
                  localXMPPConnection.sendPacket(new Presence(Presence.Type.available));
                  localRoster = localXMPPConnection.getRoster();
                  localIterator = localRoster.getEntries().iterator();
                  boolean bool = localIterator.hasNext();
                  if (bool)
                    break label655;
                  CustomServiceActivity.this.dismissLoadingDialog();
                  return;
                  localXMPPException1 = localXMPPException1;
                  LogUtils.e(CustomServiceActivity.this.TAG, "Failed to connect to " + localXMPPConnection.getHost());
                  LogUtils.e(CustomServiceActivity.this.TAG, localXMPPException1.toString());
                  CustomServiceActivity.this.setConnection(null);
                  break;
                  CustomServiceActivity.this.USERNAME = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, CustomServiceActivity.this.USERNAME);
                  CustomServiceActivity.this.userAccount = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, CustomServiceActivity.this.USERNAME);
                }
              }
            }
          }
          catch (XMPPException localXMPPException2)
          {
            while (true)
            {
              LogUtils.e(CustomServiceActivity.this.TAG, "Failed to log in as " + CustomServiceActivity.this.USERNAME);
              LogUtils.e(CustomServiceActivity.this.TAG, localXMPPException2.toString());
              CustomServiceActivity.this.setConnection(null);
              continue;
              CustomServiceActivity.this.USERNAME = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, CustomServiceActivity.this.USERNAME);
              CustomServiceActivity.this.userAccount = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_USERNAME, CustomServiceActivity.this.USERNAME);
              CustomServiceActivity.this.PASSWORD = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_PWD, CustomServiceActivity.this.PASSWORD);
            }
          }
          catch (Exception localException)
          {
            while (true)
            {
              Roster localRoster;
              Iterator localIterator;
              localException.printStackTrace();
              continue;
              System.out.println("匿名登录");
              CustomServiceActivity.this.USERNAME = "anonymous";
              CustomServiceActivity.this.PASSWORD = "anonymous";
              continue;
              label655: RosterEntry localRosterEntry = (RosterEntry)localIterator.next();
              LogUtils.d(CustomServiceActivity.this.TAG, "--------------------------------------");
              LogUtils.d(CustomServiceActivity.this.TAG, "RosterEntry " + localRosterEntry);
              LogUtils.d(CustomServiceActivity.this.TAG, "User: " + localRosterEntry.getUser());
              LogUtils.d(CustomServiceActivity.this.TAG, "Name: " + localRosterEntry.getName());
              LogUtils.d(CustomServiceActivity.this.TAG, "Status: " + localRosterEntry.getStatus());
              LogUtils.d(CustomServiceActivity.this.TAG, "Type: " + localRosterEntry.getType());
              Presence localPresence = localRoster.getPresence(localRosterEntry.getUser());
              LogUtils.d(CustomServiceActivity.this.TAG, "Presence Status: " + localPresence.getStatus());
              LogUtils.d(CustomServiceActivity.this.TAG, "Presence Type: " + localPresence.getType());
              if (localPresence.getType() == Presence.Type.available)
                LogUtils.d(CustomServiceActivity.this.TAG, "Presence AVIALABLE");
              LogUtils.d(CustomServiceActivity.this.TAG, "Presence : " + localPresence);
            }
          }
        }
      }
    }).start();
  }

  public boolean dispatchKeyEvent(KeyEvent paramKeyEvent)
  {
    if ((paramKeyEvent.getKeyCode() == 4) && (paramKeyEvent.getAction() == 0) && (paramKeyEvent.getRepeatCount() == 0))
    {
      if (this.lin_face.getVisibility() == 0)
      {
        this.lin_face.setVisibility(8);
        closeWindowSoftInput(getCurrentFocus());
        return true;
      }
      CustomApplication.app.finishActivity(this);
    }
    return super.dispatchKeyEvent(paramKeyEvent);
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    case 2131100038:
    default:
      return;
    case 2131100037:
      closeWindowSoftInput(this.edit_text_input);
      setLinFaceIsVisible();
      return;
    case 2131100039:
      sendMsg();
      return;
    case 2131100036:
      sendMsg();
      return;
    case 2131100034:
      initFace();
      return;
    case 2131100035:
    }
    initEmoji();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    customServiceActivity = this;
    this.context = this;
    this.contentView = LayoutInflater.from(this.context).inflate(2130903052, null);
    setContentView(this.contentView);
    Bundle localBundle = getIntent().getExtras();
    if (localBundle != null)
    {
      if (localBundle.containsKey("roomId"))
        this.roomId = localBundle.getString("roomId");
      this.roomId += "|kefu";
    }
    CustomApplication.app.addActivity(this);
    this.chatMessageUtil = ChatMessageUtil.getInstance(this.context);
    initUserData();
    init();
    connectToXmpp();
    initFace();
  }

  protected void onDestroy()
  {
    super.onDestroy();
    disConnectionToXmpp();
  }

  protected void sendMeg(String paramString)
  {
    System.out.println("表情" + paramString);
    org.jivesoftware.smack.packet.Message localMessage = new org.jivesoftware.smack.packet.Message(this.customer + "@" + HOST, Message.Type.chat);
    localMessage.setMessagetype("3");
    localMessage.setMemberid(this.memberid);
    localMessage.setRoomid("0");
    localMessage.setMessagedirect("1");
    localMessage.setBody(paramString);
    localMessage.setFrom(this.USERNAME + "@" + HOST);
    try
    {
      if (this.connection == null)
      {
        LogUtils.e(this.TAG, "connection = null");
        this.myDialogCancelAndOk.setMessage("聊天连接失败，确认是否重连");
        this.myDialogCancelAndOk.show();
        this.myDialogCancelAndOk.btn_confirm.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            CustomServiceActivity.this.myDialogCancelAndOk.dismiss();
            CustomServiceActivity.this.connectToXmpp();
          }
        });
        return;
      }
      this.connection.sendPacket(localMessage);
      ChatMsgEntity localChatMsgEntity = new ChatMsgEntity();
      localChatMsgEntity.setBody(paramString);
      localChatMsgEntity.setMessagetype("3");
      localChatMsgEntity.setMemberid(this.memberid);
      localChatMsgEntity.setPicurl(this.userLogo);
      localChatMsgEntity.setNickname(this.nickname);
      localChatMsgEntity.setUser_name(this.USERNAME);
      localChatMsgEntity.setSendtime(DateUtil.getNowTime());
      localChatMsgEntity.setComMsg(1);
      this.data.add(localChatMsgEntity);
      this.edit_text_input.setText("");
      closeWindowSoftInput(this.edit_text_input);
      refeshListView();
      LogUtils.e(this.TAG, "存入发送的消息");
      this.chatMessageUtil.addMessage(this.USERNAME, localChatMsgEntity);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void setConnection(XMPPConnection paramXMPPConnection)
  {
    this.connection = paramXMPPConnection;
    if (this.connection != null)
    {
      MessageTypeFilter localMessageTypeFilter = new MessageTypeFilter(Message.Type.chat);
      this.connection.addPacketListener(this.packetListener, localMessageTypeFilter);
    }
  }

  @SuppressLint({"NewApi"})
  public void setTitle(int paramInt1, int paramInt2, int paramInt3, String paramString, int paramInt4, int paramInt5, int paramInt6, int paramInt7, boolean paramBoolean)
  {
    View localView = findViewById(2131099716);
    if (paramBoolean)
      localView.setVisibility(0);
    while (true)
    {
      ((TextView)localView.findViewById(2131099701)).setText(paramString);
      ((TextView)localView.findViewById(2131099700)).setVisibility(paramInt1);
      ImageView localImageView = (ImageView)localView.findViewById(2131099699);
      localImageView.setVisibility(paramInt2);
      localImageView.setOnClickListener(this.onClickListener);
      localImageView.setImageResource(paramInt3);
      TextView localTextView = (TextView)localView.findViewById(2131099702);
      localTextView.setVisibility(paramInt5);
      localTextView.setOnClickListener(this.onClickListener);
      this.iv_title_right = ((ImageView)localView.findViewById(2131099704));
      this.iv_title_right.setVisibility(paramInt6);
      this.iv_title_right.setOnClickListener(this.onClickListener);
      this.iv_title_right.setImageResource(paramInt7);
      return;
      localView.setVisibility(8);
    }
  }

  private class EmojiPagerAdapter extends FragmentPagerAdapter
  {
    public EmojiPagerAdapter(FragmentManager arg2)
    {
      super();
    }

    public int getCount()
    {
      if (CustomServiceActivity.this.emojifragments == null)
        return 0;
      return CustomServiceActivity.this.emojifragments.size();
    }

    public Fragment getItem(int paramInt)
    {
      return (Fragment)CustomServiceActivity.this.emojifragments.get(paramInt);
    }

    public int getItemPosition(Object paramObject)
    {
      return -2;
    }
  }

  private class ViewPagerAdapter extends FragmentPagerAdapter
  {
    public ViewPagerAdapter(FragmentManager arg2)
    {
      super();
    }

    public int getCount()
    {
      if (CustomServiceActivity.this.fragments == null)
        return 0;
      return CustomServiceActivity.this.fragments.size();
    }

    public Fragment getItem(int paramInt)
    {
      return (Fragment)CustomServiceActivity.this.fragments.get(paramInt);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tabIndex.CustomServiceActivity
 * JD-Core Version:    0.6.2
 */